﻿using Sidvall.Serialization;

namespace Sidvall.IdentityManager.Security
{
    public static class SecurityManager
    {
        #region Public Members

        public const string ConfirmEmailTokenPurpose = "Confirmation";
        public const string ResetPasswordTokenPurpose = "ResetPassword";

        public const string ClientRedirectAddress = "oob://localhost/wpfclient";
        public const string Scope = "openid profile email phone offline_access";
        public const string ResponseType = "code id_token token";

        #region AuthorizeEndpoint

        public static string AuthorizeEndpoint
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved))
                    return Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved.TrimEnd('/').Append("connect/authorize", "/");
                return null;
            }
        }

        #endregion
        #region AuthorityUserInfoEndpoint

        public static string AuthorityUserInfoEndpoint
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved))
                    return Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved.TrimEnd('/').Append("connect/userinfo", "/");
                return null;
            }
        }

        #endregion
        #region AuthorityTokenEndpoint

        public static string AuthorityTokenEndpoint
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved))
                    return Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved.TrimEnd('/').Append("connect/token", "/");
                return null;
            }
        }

        #endregion
        #region LogOffEndpoint

        public static string LogOffEndpoint
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved))
                    return Sidvall.IdentityManager.Configuration.SettingsManager.STSBaseAddressResolved.TrimEnd('/').Append("connect/endsession", "/");
                return null;
            }
        }

        #endregion

        #region CreateSecurityStamp

        public static string CreateSecurityStamp()
        {
            return System.Guid.NewGuid().ToString();
        }

        #endregion

        #endregion
    }
}
